package com.example.bidserver.controller;

import com.example.bidserver.params.BidParams;
import com.example.bidserver.params.PageBidParams;
import com.example.bidserver.service.BidService;
import com.example.bidserver.vo.BidVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/bid-server")
@Api(tags = "出价接口")
public class BidController {
    @Autowired
    private BidService bidService;

    @ApiOperation(value = "获取对我的出价")
    @PostMapping(value = "/pageByUserId")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<BidVO>> pageByUserId(@RequestBody PageBidParams pageBidParams) {
        return new Result(bidService.pageByUserId(pageBidParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取我的出价")
    @PostMapping(value = "/pageByPostId")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<BidVO>> pageByPostId(@RequestBody PageBidParams pageBidParams) {
        return new Result(bidService.pageByPostId(pageBidParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取出价")
    @PostMapping(value = "/pageByGoodsId")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<BidVO>> pageByGoodsId(@RequestBody PageBidParams pageBidParams) {
        return new Result(bidService.pageByGoodsId(pageBidParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除出价")
    @PostMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteBid(@RequestParam String id) {
        bidService.deleteBid(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改出价")
    @PutMapping(value = "/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateBid(@RequestBody BidParams bidParams) {
        return new Result(bidService.updateBid(bidParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增出价")
    @PostMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertBid(@RequestBody BidParams bidParams) {
        return bidService.insertBid(bidParams);
    }
}
